#include <func.h>

struct student {
	int id;
	char name[25];
};

void* start_routine(void* arg) {
	printf("new thread: Begin\n");
	sleep(3);
	printf("new thread: End\n");
	// return (void*)9527;
	// pthread_exit((void*)10086);
	// struct student s1 = {1, "xixi"};
	struct student* s = (struct student*)malloc(sizeof(struct student));
	s->id = 1;
	strcpy(s->name, "xixi");
	pthread_exit(s);
}

int main(int argc, char* argv[])
{
	int err;
	pthread_t tid;
	err = pthread_create(&tid, NULL, start_routine, NULL);
	if (err) {
		error(1, err, "pthread_create");
	}

	// 连接新线程
	struct student* s;
	err = pthread_join(tid, (void**)&s); // 阻塞，等待tid结束
	if (err) {
		error(1, err, "pthread_join");
	}

	// printf("new thread terminated, retval = %d\n", retval);
	printf("new thread terminated, retval = {%d, %s}\n",
		   s->id, s->name);

	free(s);
    return 0;
}

